<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>改变上下文</title>
	</head>
	<body>
		<p>将函数 fn 的执行上下文改为 obj，返回 fn 执行后的值 </p>
		<p>输入例子:alterContext(function() {return this.greeting + ', ' + this.name + '!'; }, {name: 'Rebecca', greeting: 'Yo' })</p>
		<p>输出例子:Yo, Rebecca!</p>
		<script type="text/javascript">
			function alterContext(fn, obj) {
				return fn.apply(obj);
			}
			console.log(alterContext(function() {
				return this.greeting + ', ' + this.name + '!'; 
			}, {name: 'Rebecca', greeting: 'Yo' }
			));
		</script>
	</body>
</html>
